package com.cw.jeeyt.service.converter.security;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.security.SecurityLoginLogBo;
import com.cw.jeeyt.dao.model.security.SecurityLoginLogDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 登陆日志转换类
 *
 * @author chenw
 * @date 2019-03-10 13:01:34
 */
public class SecurityLoginLogConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SecurityLoginLogBo do2Bo(SecurityLoginLogDo model) {
        if (model == null) {
            return null;
        }
        String isSuccessCn = StringUtil.isNotBlank(model.getIsSuccess()) ? EnumYn.find(model.getIsSuccess())
            .getDescription() : "";
        SecurityLoginLogBo bo = new SecurityLoginLogBo();
        bo.setId(model.getId());
        bo.setUserId(model.getUserId());
        bo.setUserName(model.getUserName());
        bo.setLoginTime(model.getLoginTime());
        bo.setLoginIp(model.getLoginIp());
        bo.setIsSuccess(model.getIsSuccess());
        bo.setIsSuccessCn(isSuccessCn);
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setLogOutTime(model.getLogOutTime());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SecurityLoginLogDo bo2Do(SecurityLoginLogBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityLoginLogDo model = new SecurityLoginLogDo();
        model.setId(bo.getId());
        model.setUserId(bo.getUserId());
        model.setUserName(bo.getUserName());
        model.setLoginTime(bo.getLoginTime());
        model.setLoginIp(bo.getLoginIp());
        model.setIsSuccess(bo.getIsSuccess());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setLogOutTime(bo.getLogOutTime());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SecurityLoginLogBo> doList2BoList(List<SecurityLoginLogDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityLoginLogConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SecurityLoginLogDo> boList2DoList(List<SecurityLoginLogBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityLoginLogConverter::bo2Do));
    }
}
